<script>

import OutboundRecordPickingForm from './OutboundRecordPickingForm.vue'
import OutboundRecordPickingAuditForm from './OutboundRecordPickingAuditForm.vue'
import OutboundRecordNewForm from '@views/wms/outbound-order/modules/OutboundRecordNewForm.vue'

export default {
  name: 'OutboundRecordAuditForm',
  components: { OutboundRecordNewForm, OutboundRecordPickingAuditForm, OutboundRecordPickingForm },
  props: {
    customFormData: {
      type: Object,
      default: () => {
        return {}
      },
      required: false
    }
  },
  data() {
    return {
      disableSubmit: false,
      model: {}
    }
  },
  created() {
    // 如此判断，可能会有问题
    if (this.customFormData.id != null) {
      this.model = this.customFormData
      this.$nextTick(() => {
        if (this.isInitiator) {
          this.$refs.realForm.edit(this.model)
        } else
        if (this.isPicking) {
          this.$refs.realForm.picking(this.model)
        } else if (this.isAudit) {
          this.$refs.realForm.audit(this.model)
        }
      })
    }
  },
  computed: {
    isInitiator() {
      const { taskName } = this.model
      return taskName === '发起人'
    },
    isPicking() {
      const { pickingStatus, outboundType } = this.model
      // return ['1', '3'].includes(pickingStatus) && ![4, 5].includes(outboundType)
      return ['1', '3', '4', '5'].includes(pickingStatus)
    },
    isAudit() {
      const { pickingStatus } = this.model
      return pickingStatus === '2'
    }
  },
  methods: {
    handleOk() {
      this.$refs.realForm.handleSubmit()
    },
    submitCallback() {
      this.$emit('ok')
    }
  }
}
</script>

<template>
  <outbound-record-new-form
    ref="realForm"
    v-if="isInitiator"
    @ok="submitCallback"
    :disabled="true" />
  <outbound-record-picking-form
    ref="realForm"
    v-else-if="isPicking"
    :disabled="disableSubmit"
    @ok="submitCallback" />
  <outbound-record-picking-audit-form
    ref="realForm"
    v-else-if="isAudit"
    :disabled="disableSubmit"
    @ok="submitCallback" />
</template>

<style scoped>

</style>